<template>
	<view class="order_home">
		<!-- 广告区域 -->
		<advers_list :advers="swipers"></advers_list>

		<!-- 顶部栏目 -->
		<view class="top">
			<view :class="actives === 1?'active':''" @click="select()">任务大厅</view>
			<view @click="select_navigator()">我的发布</view>
		</view>

		<!-- 任务大厅区域 -->
		<view class="task" v-for="item in TaskIofo" :key="item.id" v-if="(show === 1 && (item.select_paoshou == ''?true:false))"
		 @click="TaskNavigation(item.id)">
			<view class="task_item">
				<text class="desc" style="">取快递({{item.take_item}}{{item.type}})到{{item.give_item}} </text>
				<text class="money" style="" :decode="true">奖励:{{money(item.size)}}</text></view>
			<!-- <view class="iconfont icon-jiantou"></view> -->
		</view>

		<view class="bottom">
			没有更多内容了哦~
		</view>
	</view>
</template>

<script>
	import advers_list from '../../components/advertisement/advertisement.vue';
	export default {
		data() {
			return {
				swipers: [{
						id: 1,
						img: "../../static/temp/temp1.jpg"
					},
					{
						id: 2,
						img: "../../static/temp/temp2.jpg"
					},
					{
						id: 3,
						img: "../../static/temp/temp3.jpg"
					}
				],
				show: 1,
				actives: 1,
				TaskIofo: [],
				User: {},
				Temp: 0
			}
		},
		onShow() {
			uni.$on('Sgin_Out', () => {
				this.User= JSON.parse(uni.getStorageSync('userInfo') || '{}') ;
				this.name = '用户昵称(点击注册登录)';
				this.ride = '../../static/temp/Riding.png';
				this.login = '../../pagesD/login_register/login_register';
			    this.head = '../../static/temp/head1.png';
			})
		},
		methods: {
			async getTaskInfo() {
				const res = await this.$myRequest({
					url: 'getTaskInfo'
				})
				this.TaskIofo = res.data.message;
				getApp().globalData.All_Task = this.TaskIofo;
			},
			select(index) {
				this.show = 1;
				this.actives = 1;
			},
			select_navigator() {
				this.User= JSON.parse(uni.getStorageSync('userInfo') || '{}' ) ;
				if ((JSON.stringify(this.User)) == '{}' || this.User === undefined) {
					uni.showToast({
						title: '你还未登录哦',
						icon:'none'
					})
					uni.navigateTo({
						url:'/pagesD/login_register/login_register'
					})
					return;
				}

				if (this.User.code == 0) {
					this.show = 1;
					this.actives = 1;
					let number = this.User.message.student_number;
					// let number = 'B20190306118'
					uni.navigateTo({
						url: '../../pagesF/Task/Task?number=' + number
					})
				} else {
					this.show = 1;
					this.actives = 1;

					let number = this.User.student_number;
					// let number = 'B20190306118'
					uni.navigateTo({
						url: '../../pagesF/Task/Task?number=' + number
					})
				}

			},
			TaskNavigation(id) {
				this.User = JSON.parse(uni.getStorageSync('userInfo') || '{}') ;
				// console.log(this.User,'新')

				if ((JSON.stringify(this.User)) == '{}') {
					uni.showToast({
						title: '你还未登录哦',
						icon:'none'
					})
					return;
				}

				if (this.User.code == 0) {
					if (this.User.message.if_runner == 0) {
						uni.showToast({
							title: '你还不是跑手哦',
							icon:'none'
						})
						return;
					}
					// console.log(this.User.message.student_number,'能得到用户学号嘛');
					let address = '../../pagesB/details/details';
					uni.navigateTo({
						url: `${address}?id=${id}&number=${this.User.message.student_number}`
					})
				} else {
					if (this.User.if_runner == 0) {
						uni.showToast({
							title: '你还不是跑手哦',
							icon:'none'
						})
						return;
					}
					// console.log(this.User.message.student_number,'能得到用户学号嘛');
					let address = '../../pagesB/details/details';
					uni.navigateTo({
						url: `${address}?id=${id}&number=${this.User.student_number}`
					})
				}

			}
		},
		components: {
			"advers_list": advers_list
		},
		onLoad() {
			this.getTaskInfo();
		},
		onPageScroll() {
			this.TaskIofo = getApp().globalData.All_Task;
		},
		onShow() {
			this.getTaskInfo();
		},
		computed: {
			money() {
				return (index) => {
					if (index === '小') {
						return '2元'
					} else if (index === '中') {
						return '3元'
					} else if (index === '大') {
						return '5元'
					} else {
						return '10元'
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.order_home {
		.top {
			width: 750rpx;
			display: flex;

			view {
				width: 50%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 28rpx;
				// background: #4CD964;
				color: #333;
				// border-radius: 50rpx;

			}

			.active {
				background: $main-color;
				font-weight: 700;
				color: #FFFFFF;
			}
		}

		.task {
			display: flex;
			justify-content: space-between;
			border: 1px solid red;
			padding: 25rpx;

			view {
				font-size: 40rpx;
				line-height: 50rpx;
			}

			border: 1px solid #eee;

			.task_item {
				display: flex;
				color: #666;
				font-size: 30rpx;

				.desc {
					flex: 3;
					padding-right: 20rpx;
				}

				.money {
					display: flex;
					flex: 1;
					width: 150rpx;
					height: 54rpx;
					background-image: linear-gradient(to right, #00C2FF, #007aff);
					border-radius: 10rpx;
					justify-content: center;
					color: #FFFFFF;
					font-size: 30rpx;
				}

			}
		}

		.bottom {
			width: 100%;
			border: 1px solid #E4E7ED;
			height: 50px;
			line-height: 50px;
			text-align: center;
			font-size: 15px;
			color: #C8C7CC;
		}
	}
</style>
